layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
		
	setTimeout(function(){
				form.render('checkbox',"test1");

		},100);
    form.on("submit(addRole)",function(data){
		var roles=new Array(data.field.length);
		var i = 0;
		for(var key in data.field){
			var pdata={
				"name":key,
			}
			roles[i]=pdata;
			i++;
		}
		var roles_data=JSON.stringify(roles);
        var data={
			"id":$(".id").val(),
			"name":$(".roleName").val(),
			"permissions":roles
		}
		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});

		var url=global_url+'/admin/addRole'
		if($(".id").val()!=""){
			 url=global_url+'/admin/updateRole'
		}
		
		Vue.http.post(url,data).then(
			response=>{
					top.layer.close(index);
					layer.closeAll("iframe");
					top.layer.msg(response.body.datas);
					//刷新父页面
					parent.location.reload();
					
			},
			response=>{
				top.layer.close(index);
				layer.closeAll("iframe");
				top.layer.msg(response.body.datas);
				//刷新父页面
				parent.location.reload();
			}
		);
		
		
		return false;
    })

 
})